package cn.iocoder.yudao.module.kt.controller.admin.chatmessageketang;

import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.kt.controller.admin.chatmessageketang.vo.*;
import cn.iocoder.yudao.module.kt.dal.dataobject.chatmessageketang.ChatMessageKetangDO;
import cn.iocoder.yudao.module.kt.service.chatmessageketang.ChatMessageKetangService;

@Tag(name = "管理后台 - 数字人课堂聊天消息记录")
@RestController
@RequestMapping("/kt/chat-message-ketang")
@Validated
public class ChatMessageKetangController {

    @Resource
    private ChatMessageKetangService chatMessageKetangService;

    @PostMapping("/create")
    @Operation(summary = "创建数字人课堂聊天消息记录")
    @PreAuthorize("@ss.hasPermission('kt:chat-message-ketang:create')")
    public CommonResult<Long> createChatMessageKetang(@Valid @RequestBody ChatMessageKetangSaveReqVO createReqVO) {
        return success(chatMessageKetangService.createChatMessageKetang(createReqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除数字人课堂聊天消息记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('kt:chat-message-ketang:delete')")
    public CommonResult<Boolean> deleteChatMessageKetang(@RequestParam("id") Long id) {
        chatMessageKetangService.deleteChatMessageKetang(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得数字人课堂聊天消息记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('kt:chat-message-ketang:query')")
    public CommonResult<ChatMessageKetangRespVO> getChatMessageKetang(@RequestParam("id") Long id) {
        ChatMessageKetangDO chatMessageKetang = chatMessageKetangService.getChatMessageKetang(id);
        return success(BeanUtils.toBean(chatMessageKetang, ChatMessageKetangRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得数字人课堂聊天消息记录分页")
    @PreAuthorize("@ss.hasPermission('kt:chat-message-ketang:query')")
    public CommonResult<PageResult<ChatMessageKetangRespVO>> getChatMessageKetangPage(@Valid ChatMessageKetangPageReqVO pageReqVO) {
        PageResult<ChatMessageKetangDO> pageResult = chatMessageKetangService.getChatMessageKetangPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ChatMessageKetangRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出数字人课堂聊天消息记录 Excel")
    @PreAuthorize("@ss.hasPermission('kt:chat-message-ketang:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportChatMessageKetangExcel(@Valid ChatMessageKetangPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ChatMessageKetangDO> list = chatMessageKetangService.getChatMessageKetangPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "数字人课堂聊天消息记录.xls", "数据", ChatMessageKetangRespVO.class,
                        BeanUtils.toBean(list, ChatMessageKetangRespVO.class));
    }

}